import requests
import time
import random
#获取token
def get_token():
    url = 'http://hxzhan.rtcloud.com:32111/sso/api/v1/common/login'
    headers = {
        'content-type':'application/json; charset=utf-8'
    }
    json = {"username":"xiaoqing","password":"N4aGDzp6idb9VbQP6UN77WWUxaw91m1/trWr7qKoy/ewOb6ax5UfKIfvA4qWqWgm"}
    response = requests.post(url=url,headers=headers,json=json)
    return response.json()['data']['token']
def get_time():
    return str(int(time.time()))
def get_id():
    return str(random.randint(1,10000000000))
#获取用户详情
def get_userinfo():
    url = 'http://hxzhan.rtcloud.com:32111/tm/roles/user/info'
    headers = {
        'content-type':'application/json; charset=utf-8',
        'Tm-Token':get_token(), 
        'rt-request-ts':str(int(time.time())),
        'rt-request-id':str(random.randint(1,10000000000))
    }
    response = requests.get(url=url,headers=headers)
    return response.json()['data']   
#获取首页顶部站点、网络等数据
def get_toplist():
    url = 'http://hxzhan.rtcloud.com:32111/tm/home/overview'
    headers = {
        'content-type':'application/json; charset=utf-8',
        'Tm-Token':get_token(), 
        'rt-request-ts':str(int(time.time())),
        'rt-request-id':str(random.randint(1,10000000000))
    }
    response = requests.post(url=url,headers=headers)
    return response.json()['data']
#获取首页列表告警数据
def get_alarlist():
    url = ' http://hxzhan.rtcloud.com:32111/tm/alarm/list'
    headers = {
        'content-type':'application/json; charset=utf-8',
        'Tm-Token':get_token(), 
        'rt-request-ts':str(int(time.time())),
        'rt-request-id':str(random.randint(1,10000000000))
    }
    json = {'page': 1, 'limit': 6}
    response = requests.post(url=url,headers=headers,json=json)
    return response.json()['data']['list']
#获取首页站点数据
def get_site(type,status):
    url = 'http://hxzhan.rtcloud.com:32111/tm/home/station/overview'
    headers = {
        'content-type':'application/json; charset=utf-8',
        'Tm-Token':get_token(), 
        'rt-request-ts':str(int(time.time())),
        'rt-request-id':str(random.randint(1,10000000000))
    }
    json = {'page': 1, 'limit': 100,'status':status}
    response = requests.post(url=url,headers=headers,json=json)
    if type == 'site':
        return response.json()['data']['list']
    elif type == 'number':
        return response.json()['data']['nums']

